<%@ page language="java" contentType="text/html; charset=UTF-8"  
    pageEncoding="UTF-8"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>comet</title>  
<script type="text/javascript" src="jquery-1.11.1.js"></script>  
<script type="text/javascript" src="comet4j.js"></script>  
  
<script type="text/javascript">  
   
$(function(){  
    JS.Engine.on('hello', function(text){   
        $("#targetDiv").append("<span id='msgSpan' style='color:red'>" + text + "</span>");  
    });  
      
    <%  
       // String userId = request.getParameter("userId");  
        String userId = "123456"; 
        session.setAttribute("currentUserId", userId);  
    %>  
  
    JS.Engine.start('conn');  
});  
  
$(document).ready(function(){  
    $("#targetDiv").bind("click", function(){  
        //有新消息  
        if ($(this).find("span").length > 0) {  
            $("div > span").remove();  
        }  
    });  
});   
  
</script>  
</head>  
<body>  
    <table border="1" width:600px>  
        <tr>  
            <td>hello comet</td>  
            <td><div id="targetDiv" style="width:300px"></div></td>  
        </tr>  
    </table>  
</body>  
</html>  